<?php
namespace App\Modules\Role;

use App\Modules\AdapterApi;
use App\Services\User\UserIndex;
/**
 * 对角色管理的操作
 * @author adv30 <adv30@126.com> \app\serverauth\service\role\Role
 */
class Role extends AdapterApi
{
    // 增加一个角色
    public function add(): array
    {
        $data = pick_array($this->postData, ['name','name_cn','weight','department_id']);

        return UserIndex::Role()->add($data);
    }
    // 停用一个角色
    public function stop(): array
    {
        $data = pick_array($this->postData, ['id','name']);

        return UserIndex::Role()->stop($data);
    }
    // 启用一个角色
    public function start(): array
    {
        $data = pick_array($this->postData, ['id','name']);

        return UserIndex::Role()->start($data);
    }
    // 获取角色列表分页数据
    public function list(): array
    {
        $data = pick_array($this->postData, ['page', 'list_rows', 'status']);

        return UserIndex::Role()->list($data);
    }
    // 获取角色列表分页数据
    public function edit(): array
    {
        $data = pick_array($this->postData,['id','name','name_cn','weight','menu']);

        return UserIndex::Role()->edit($data);
    }
    // 用户申请某个角色
    public function apply(): array
    {
        $data = pick_array($this->postData,['app_id', 'user_id', 'role_id', 'apply_info']);

        return UserIndex::Role()->apply($data);
    }
    // 获取当前可以申请的角色
    public function allowApply(): array
    {
        $data = pick_array($this->postData,['app_id','user_id']);

        return UserIndex::Role()->allowApply($data);
    }
    // 审核用户申请的角色
    public function audit(): array
    {
        $data = pick_array($this->postData,['id','pass_user_id']);

        return UserIndex::Role()->audit($data);
    }
    // 给某一个用户某角色
    public function giveRoles(): array
    {
        $data = pick_array($this->postData,['id', 'name', 'phone', 'role_id']);

        return UserIndex::User()->giveRoles($data);
    }
    // 获取不分页的所有角色列表
    public function all(): array
    {
        return UserIndex::Role()->all();
        return $this->oneStepRun([], 'serveruser/auth/Role/all', 'all');
    }
    // 获取某一应用下的所有的角色列表
    public function allRolesByApp(): array
    {
        $data = pick_array($this->postData,['id', 'name', 'app_key']);
        return UserIndex::Role()->allRolesByApp($data);
        return $this->oneStepRun($data, 'serveruser/auth/Role/allRolesByApp', 'allRolesByApp');
    }
    // 移除某用户的某角色
    public function removeUserRole(): array
    {
        $data = pick_array($this->postData,['id','name','phone','role_id']);

        return UserIndex::User()->removeUserRole($data);
    }
    // 获取某个角色的详情
    public function getRoleInfo(): array
    {
        $data = pick_array($this->postData,['id']);

        return UserIndex::Role()->getRoleInfo($data);
    }
}